<template>
  <div class="hello">
    <div style="background-color: #f1f1f0; width: 100%; padding: 15px 0">
      <div
        style="
          display: flex;
          justify-content: space-between;
          width: 90%;
          margin: 0 auto;
        "
      >
        <div style="width: 50%; display: flex; align-items: center">
          <div style="width: 20px">
            <img src="../assets/img6.png" width="100%" />
          </div>
          <div style="margin-left: 4%">我的奖品</div>
        </div>
      </div>
    </div>
    <div
      style="width: 50%; text-align: center; margin: 5% auto"
      v-show="xianshi"
    >
      <van-loading />
    </div>
    <div style="text-align: center; padding: 20px" v-show="yincang">
      <div class="zwxximg" style="margin-top: 38%">
        <img src="../assets/zwxx.png" alt="" />
      </div>
      <div class="zwxx">暂无数据</div>
    </div>
    <div
      style="
        border-bottom: 1px solid #ebebeb;
        display: flex;
        align-items: center;
        width: 90%;
        margin: 0 auto;
        padding: 20px 0;
      "
      v-for="(item, index) in pricelist"
      :key="index"
    >
      <div style="width: 70px"><img :src="item.image" width="100%" /></div>
      <div
        style="
          width: 100%;
          margin-left: 10px;
          font-size: 15px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        "
      >
        <div style="font-size: 12px; color: black; font-weight: 600">
          {{ item.prize }}
        </div>
        <div
          style="
            display: flex;
            align-items: flex-end;
            justify-content: space-between;
          "
        >
          <div style="color: #c3c3c3; font-size: 12px">
            {{ item.createTime }}
          </div>
          <div class="typeStyle">
            <el-button
              size="small"
              round
              type="primary"
              v-if="item.state == 1"
              style="
                background-color: rgb(174, 174, 174);
                min-width: 78px;
                border: none;
              "
              >已兑换</el-button
            >
            <el-button
              size="small"
              round
              type="primary"
              v-if="item.state == 0"
              style="background-color: orange; border: none"
              @click="waitingFor(item)"
              >等待兑换</el-button
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "prize",
  props: {
    msg: String,
  },
  data() {
    return {
      pricelist: [],
      xianshi: true,
      yincang: false,
    };
  },
  created() {
    this.prizeList();
  },
  mounted() {
    // 返回监听事件
    // 如果支持 popstate 一般移动端都支持了
    // if (window.history && window.history.pushState) {
    //   // 往历史记录里面添加一条新的当前页面的url
    //   history.pushState(null, null, document.URL);
    //   // 给 popstate 绑定一个方法 监听页面刷新
    //   window.addEventListener("popstate", this.backChange, false); //false阻止默认事件
    // }
  },
  methods: {
    // backChange() {
    //   console.log("监听到了");
    // },
    prizeList() {
      request({
        url: "/generator/userprizes/front/userPrizes",
        method: "get",
      }).then((response) => {
        console.log(response.list);
        this.pricelist = response.list;
        this.xianshi = false;
        if (this.pricelist == "") {
          this.yincang = true;
        } else {
          this.yincang = false;
        }
        // alert(JSON.stringify(response.token));
      });
    },
    waitingFor(item) {
      console.log(item.type, "item");
      let row = {
        image: item.image,
        title: item.prize,
        id: item.id,
        prizesType:item.prizesType
      };
      console.log("跳转inpackeg", row);
        this.$router.push({
          name: "inpackeg",
          query: { row: row },
        });
    },
  },
  // destroyed() {
  //   window.removeEventListener("popstate", this.backChange, false); //false阻止默认事件
  // },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.zwxximg {
  widows: 100%;
  text-align: center;
  margin-top: 40%;
}
.zwxx {
  width: 100%;
  text-align: center;
  font-size: 20px;
}
</style>
